﻿Imports System.Data
Imports System.Data.SqlClient
Public Class Frm_Recherche_Equipements

    Private Sub Frm_Recherche_Equipements_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Gestion_Equipements.Enabled = True
        Frm_Demande_Clients_loc.Enabled = True
    End Sub

    Private Sub Frm_Recherche_Equipements_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Frm_Gestion_Equipements.Enabled = False

        comb_selectionnez.SelectedIndex = 0
    End Sub

    Private Sub txt_mot_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_mot.TextChanged
   
        Try
            List_tous.Items.Clear()
            Cmd = New SqlCommand("Select distinct Nom_Equipement,Type,Id_Equipement From Equipement where Nom_Equipement like '%" & txt_mot.Text & "%'", Con)
            open()
            Dr = Cmd.ExecuteReader()
            Do While Dr.Read()
                Dim Line As ListViewItem = New ListViewItem(New String() {Dr("Nom_Equipement"), Dr("Type"), Dr("Id_Equipement")})
                List_tous.Items.Add(Line)
            Loop
            Dr.Close()
            cnClose()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation)
            cnClose()
        End Try
        If txt_mot.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub btn_selectionnez_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_selectionnez.Click

        Dim n As Integer
        With List_tous
            If .SelectedIndices.Count > 0 Then

                For i As Integer = 0 To .SelectedIndices.Count - 1
                    n = CInt(.Items(.SelectedIndices(i)).SubItems(2).Text)
                Next
                If rechEqui = "loc" Then
                    For i As Integer = 0 To .SelectedIndices.Count - 1
                        'Frm_Demande_Clients_loc.Comb_Nom_Equipement.SelectedItem = .Items(.SelectedIndices(i)).SubItems(0).Text
                    Next
                ElseIf rechEqui = "Equip" Then
                    'For i As Integer = 0 To Frm_Gestion_Equipements.List_tous.Items.Count - 1
                    '    If Frm_Gestion_Equipements.List_tous.Items(i).SubItems(7).Text = n Then
                    '        Frm_Gestion_Equipements.List_tous.Items(i).Focused = True
                    '        Frm_Gestion_Equipements.List_tous.Items(i).Selected = True
                    '    End If
                    'Next
                End If

               
                Me.Close()

            Else
                MsgBox("Vous n'avez selectionner aucun Ligne !", MsgBoxStyle.Critical, "Réssayer !")
            End If
        End With
    End Sub

    Private Sub comb_selectionnez_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles comb_selectionnez.KeyPress
        e.Handled = True
    End Sub
End Class